import PropTypes from 'prop-types'
import React, { Component } from 'react'

export default class Field extends Component {
  state = {
    value: '',
  }
  static defaultProps = {
    label: '',
    type: 'text',
  }

  static propTypes = {
    label: PropTypes.string.isRequired,
    type: PropTypes.string,
  }

  render() {
    return (
      <div>
        <label>{this.props.label}</label>
        <input
          type={this.props.type}
          value={this.state.value}
          onChange={(evt) => this.setState({ value: evt.target.value })}
        />
      </div>
    )
  }

  clear = () => {
    this.setState({ value: '' })
  }

  setValue = (value) => {
    this.setState({ value })
  }
}
